<template>
  <div>
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle"></TopFilter>

    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :onRowSelectChange="selectChangeHandle"
      :onColumnsChange="columns => (this.columns = columns)"
    >
    </FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer(1)">取 消</el-button>
      <el-button @click="closeDrawer(2)" type="primary" :disabled="isDisabled">确 定</el-button>
    </div>
  </div>
</template>
<script>
import { vehicleConfiguration } from '@/api/omFinance';
import { queryCarList } from '@/api/dealerSale/salesPlan/PlanReportN2';

export default {
  data() {
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchApi: queryCarList,
      fetchParams: { templateStatus: 60231002 },
      saveData: [],
      isDisabled: true
    };
  },
  created() {
    this.getvehicleList();
  },
  methods: {
    async getvehicleList() {
      let res = await vehicleConfiguration(0, { isUnlimited: 10041001 });
      this.topFilterList.find(item => item.fieldName === 'brandProductList').itemList = res.data;
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, this.fetchParams, val);
    },
    closeDrawer(type) {
      if (1 == type) {
        this.$emit('close', false);
        return;
      }
      this.$emit('close', false, this.saveData);
    },
    selectChangeHandle(rows) {
      if (rows.length > 0) {
        this.saveData = rows;
        this.isDisabled = false;
        return;
      }
      this.isDisabled = true;
    },

    createdFrom() {
      return [
        {
          type: 'INPUT_CASCADER',
          label: '车型选择',
          fieldName: 'brandProductList',
          placeholder: '请选择',
          options: { titles: ['品牌', '车系', '车型', '配置', '选装'] },
          itemList: []
        },
        {
          type: 'INPUT',
          label: '选装代码',
          fieldName: 'optionCode',
          placeholder: '请选择'
        },
        {
          type: 'INPUT',
          label: '选装名称',
          fieldName: 'optionName',
          placeholder: '请选择'
        }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '品牌名称',
          dataIndex: 'brandName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车系名称',
          dataIndex: 'seriesName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车型名称',
          dataIndex: 'modelName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配置名称',
          dataIndex: 'configName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '选装代码',
          dataIndex: 'optionCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '选装名称',
          dataIndex: 'optionName',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    }
  }
};
</script>
